<?php
namespace app\command;

use app\common\model\DataRecordModel;
use app\common\model\ShopModel;
use app\stores\model\order\GoodsOrderModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Memberlock extends Command
{
    protected function configure()
    {
        $this->setName('Memberlock')
            ->addArgument('name', Argument::OPTIONAL, "your name")
            ->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
            ->setDescription('Say Hello');
    }

    protected function execute(Input $input, Output $output)
    {
        $datarecord= new DataRecordModel();
        $record_id=5;
        $record=$datarecord->where(['id'=>$record_id])->find();
        $old_edittime=empty($record)?'':$record['old_edittime'];
        $old_edittime=strtotime($old_edittime);
        $page=1;
        $num=10;
        $order['a.edit_time']='asc';
        $order['a.order_id']='asc';
        $ShopModel=new ShopModel();
        do{
            $s=[];
            $s['edit_time']=$old_edittime;
            $s['is_paid']=1;
            $s['status']=8;
            $list=GoodsOrderModel::list($s,$order,$page,$num);
            if(empty($list)){
                $output->writeln("暂无数据".var_export([$s,$order,$page],true) );exit();
            }
            foreach ($list as $v){
                $shop_id=$v['shop_id'];
                $s=[];
                $s['shop_id']=$shop_id;
                $n_shop=$ShopModel->where($s)->find();
                if($n_shop['is_lock']==1){//锁客分红开启
                    memberlock($v['order_id'],1);//锁客分红
                }
            }
            $end=end($list);
            if(strtotime($end['edit_time'])==$old_edittime){
                $page++;
            }else{
                $old_edittime=strtotime($end['edit_time']);
                $up=[];
                $up['old_edittime']=date('Y-m-d H:i:s',$old_edittime);
                DataRecordModel::up($up,['id'=>$record_id]);
            }
        }while(true);
    }
}